package com.github.edu.repair.web.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.github.admin.edu.assembly.common.entity.JsonEntity;
import com.github.admin.edu.assembly.common.util.JsonUtils;
import com.github.admin.edu.assembly.string.util.StringUtils;
import com.github.admin.edu.oauth.server.api.entity.TUserInformation;
import com.github.edu.repair.web.domain.ServiceQueryUserInformationDomain;
import com.github.edu.repair.web.service.RepairIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-9-3
 */
@Slf4j
@Service
public class RepairIndexServiceImpl implements RepairIndexService {

    /**
     * 查询用户基本信息，包含组织单位信息
     */
    @Autowired
    private ServiceQueryUserInformationDomain informationDomain;

    @Override
    public void index(ModelMap map, String userId) {
        TUserInformation userInformation = null;
        String code_user = informationDomain.getUserRoleOrgId(userId);//查询用户信息，包含角色集合，部门集合
        if (StringUtils.isNotBlank(code_user)) {
            JsonEntity<TUserInformation> jsonEntity = JsonUtils.toCollection(code_user,
                    new TypeReference<JsonEntity<TUserInformation>>() {
                    });
            if (null != jsonEntity) {
                userInformation = jsonEntity.getData();
            }
        }
        if(null==userInformation){
            userInformation=new TUserInformation();
        }
        map.put("user",userInformation);
    }
}
